<template>
  <div>
    <van-nav-bar
    title="增加菜品"
    left-text="返回"
    right-text="保存"
    left-arrow
    @click-left="$router.go(-1)"
    @click-right="save"
  />
  <span>图片：</span>
  <van-uploader v-model="fileList" multiple :max-count="1" :after-read="afterRead"/>

 
  <van-field v-model="dishName" label="菜名：" placeholder="请输入菜品名称" />
  <van-field v-model="jieshao" label="介绍：" placeholder="请输入菜品介绍" />
  <van-field v-model="price"  type="number" label="价格" placeholder="请输入菜品价格" />


  </div>
</template>

<script>
import {addDish} from '@/api/shangjia/dish'
import { mapState} from "vuex";
export default {
name:"addDish",
data() {
    return {
        dishName:'',
        jieshao:'',
        price:'',
        fileList:[],
        dishImg:''
    }
},
computed: {
      ...mapState('user', ['userInfo'])
    },
methods:{
    afterRead(file) {
      // 将上传的文件传到接口
   this.dishImg=file.file
      console.log(this.dishImg);
    },
    save(){
        if(this.dishName=='' || this.jieshao=='' || this.price==''){
            this.$toast('输入内容不能为空')
            return
        }
        console.log(this.userInfo.canteenWindowId,this.dishName,this.dishImg,this.jieshao,parseInt(this.price));
        addDish(this.userInfo.canteenWindowId,this.dishName,this.dishImg,this.jieshao,parseInt(this.price)).then((res)=>{
            // console.log(res);
            this.$toast('增加成功')
        })
    },
}

}
</script>

<style lang="less" scoped>

.van-uploader {
    margin-left: 14.66667vw;
    margin-top: 41px;
}
span{
    margin-top: 20px;
    margin-left: 16px;
}
.van-cell{
    margin-top: 40px;
}

</style>